package com.hxzy.research.controller.front;

import com.hxzy.research.pojo.TblBigitem;
import com.hxzy.research.pojo.TblItem;
import com.hxzy.research.pojo.TblSelectvalue;
import com.hxzy.research.service.pageandmanager.FrontTeach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping(value = "/front")
public class FrontTeachController {
    @Autowired private FrontTeach frontTeach;

    @RequestMapping("/teach.go")
   public ModelAndView findCourseByid(Integer pageId, Integer localId, HttpSession session)throws Exception{
        session.setAttribute("branchId",localId);
        ModelAndView mv=new ModelAndView();
        //根据分公司id查询科目 班级 教师
        mv.addObject("courseList", frontTeach.findCourseByid(localId));
        mv.addObject("classList", frontTeach.findClassByid(localId));
        mv.addObject("teacherList", frontTeach.findTeacherById(localId));
        //根据pageId查询大项

        List<TblBigitem> bigitems= frontTeach.findBigitemByPageid(pageId);  //大项
        //通过大项id查询小项


        for (TblBigitem bigitem:bigitems){
            List<TblItem> itemList= frontTeach.findItemByBigId(bigitem.getId());
            bigitem.setSubItemVOList(itemList);

            for (TblItem item:itemList){
                List<TblSelectvalue> selectvalueList= frontTeach.findSelectvalueById(item.getId());
                item.setSelectValueVOList(selectvalueList);

            }
        }
        mv.addObject("bigItems",bigitems);



        mv.setViewName("front/teach");
        return mv;
    }

}
